﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SilkeyERP.Model
{
    public partial class Products
    {

        /// <summary>
        /// Return the Current Product Sales Price With Out Tax
        /// </summary>
        /// <param name="CurrentTaxValue">Current Tax Value</param>
        /// <param name="isIncrement">Indicate if the Percentage must be incremental or decremental</param>
        /// <param name="percentage">Percentage to apply</param>
        /// <param name="CurrentBuyPriceWTax">Current Buy Price With Tax</param>
        /// <returns></returns>
        public static decimal GetSalesValueWOutTax(decimal CurrentTaxValue, bool isIncrement, decimal percentage, decimal CurrentBuyPriceWTax)
        {
            if (isIncrement)
            {
                var valorCompraSinImpuestosSinPorcentaje = (CurrentBuyPriceWTax / decimal.Parse("1." + CurrentTaxValue.ToString().Replace(".", "")));
                return valorCompraSinImpuestosSinPorcentaje + (valorCompraSinImpuestosSinPorcentaje * percentage) / 100;
            }
            else
            {
                var valorCompraSinImpuestosSinPorcentaje = (CurrentBuyPriceWTax / decimal.Parse("1." + CurrentTaxValue.ToString().Replace(".", "")));
                return valorCompraSinImpuestosSinPorcentaje - (valorCompraSinImpuestosSinPorcentaje * percentage) / 100;
            }
        }

        /// <summary>
        /// Return the Current Product Sales Price With Tax
        /// </summary>
        /// <param name="CurrentTaxValue">Current Tax Value</param>
        /// <param name="isIncrement">Indicate if the Percentage must be incremental or decremental</param>
        /// <param name="percentage">Percentage to apply</param>
        /// <param name="CurrentBuyPriceWOutTax">Current Buy Price With Out Tax</param>
        /// <returns></returns>
        public static decimal GetSalesValueWTax(decimal CurrentTaxValue, bool isIncrement, decimal percentage, decimal CurrentBuyPriceWOutTax)
        {
            if (isIncrement)
            {
                var valorCompraConImpuestosSinPorcentaje = CurrentBuyPriceWOutTax * decimal.Parse("1." + CurrentTaxValue.ToString().Replace(".", ""));
                return valorCompraConImpuestosSinPorcentaje + (valorCompraConImpuestosSinPorcentaje * percentage) / 100;
            }
            else
            {
                var valorCompraConImpuestosSinPorcentaje = (CurrentBuyPriceWOutTax * decimal.Parse("1." + CurrentTaxValue.ToString().Replace(".", "")));
                return valorCompraConImpuestosSinPorcentaje - (valorCompraConImpuestosSinPorcentaje * percentage) / 100;
            }
        }      
    }
}
